import { isShowButton } from '@/utils/util';
import User from './component/User';

const currentPermissions = JSON.parse(localStorage.getItem('currentPermissions'));

export const columns = ({ handleEdit }) => [
  {
    title: '用户昵称/编号',
    dataIndex: 'consumerName',
    hideInTable: true,
  },
  {
    title: '手机号码',
    dataIndex: 'mobile',
    hideInTable: true,
  },
  {
    title: '用户信息',
    dataIndex: 'consumerName',
    align: 'left',
    hideInSearch: true,
    render: (_, record) => (
      <User
        headUrl={record.headUrl}
        name={record.consumerName}
        code={record.consumerCode}
        phone={record.mobile}
      />
    ),
  },
  {
    title: '积分总量',
    dataIndex: 'pointsTotal',
    align: 'left',
    hideInSearch: true,
  },
  {
    title: '积分余额',
    dataIndex: 'pointsAvailable',
    align: 'left',
    hideInSearch: true,
  },
  {
    title: '操作',
    align: 'left',
    hideInSearch: true,
    render: (record) => (
      <div>
        {isShowButton(currentPermissions, 'cust:userIntegralManage:userIntegralInfo') && (
          <a style={{ marginRight: 8 }} onClick={() => handleEdit('detail', record)}>
            积分明细
          </a>
        )}
        {isShowButton(currentPermissions, 'cust:userIntegralManage:edit') && (
          <a onClick={() => handleEdit('edit', record)}>修改积分</a>
        )}
      </div>
    ),
  },
];
